from member_list import MEMBER_LIST
import argparse
import pickle

parser = argparse.ArgumentParser()
parser.add_argument("-i","--init",
                    help="Init the member list.")
args = parser.parse_args()

if args.init:
    print "Current is: %s" % args.init
    for i, member in enumerate(MEMBER_LIST):
        if member == args.init:
            ll = [member] + MEMBER_LIST[i+1:] + MEMBER_LIST[0:i]
            with open('jar', 'w') as member_queue:
                pickle.dump(ll, member_queue)
            print "Next is: %s" % ll[-1]
else:
    with open('jar', 'r') as member_queue:
        members = pickle.load(member_queue)
        current =  members.pop()
        members.insert(0, current)
        print "Current is: %s" % current
        print "Next is: %s" % members[-1]

    with open('jar', 'w') as member_queue:
        pickle.dump(members, member_queue)
